package org.niu.array;

import java.util.*;

public class NextGreaterEle {
        public int[] nextGreaterElement(int[] nums1, int[] nums2) {
            List<Integer> list = new ArrayList<>();
            int[] ans = new int[nums1.length];
            for (int num : nums2) {
                list.add(num);
            }
            int k = 0;
            boolean flag = false;
            for (int i : nums1) {
                int i1 = list.indexOf(i);
                if(i1==nums2.length-1){
                    ans[k++]=-1;
                }else{
                    for (int j = i1; j < nums2.length; j++) {
                        if(nums2[j] > i){
                            ans[k++]=nums2[j];
                            flag = true;
                            break;
                        }
                    }
                }
                if(!flag){
                    ans[k++]=-1;
                }
                if(flag) flag = false;
            }
            return ans;
    }
}
